package com.silence.demo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * HelloWorld
 * @author Silence
 * @version 1.0.0
 *
 */
@Api(value = "Helloworld", description = "Helloworld" )
@Controller
public class HelloController {

    @ApiOperation(value="HelloWorld", notes="")
    @RequestMapping(value="/hello",method= RequestMethod.GET)
    public String index() {
        return "Hello World";
    }

    @ApiOperation(value="测试thymeleaf", notes="")
    @RequestMapping(value="/thymeleaf",method= RequestMethod.GET)
    public String thymeleaf(ModelMap map) {
        // 加入一个属性，用来在模板中读取
        map.addAttribute("host", "http://liu.silence.com");
        // return模板文件的名称，对应src/main/resources/templates/demo/thymeleaf.html
        return "demo/thymeleaf";
    }

    @ApiOperation(value="测试异常", notes="")
    @RequestMapping(value="/exception",method= RequestMethod.GET)
    public String exception() throws Exception {
        throw new Exception("发生错误");
    }


}